home *** CD-ROM | disk | FTP | other *** search
- % Copyright (C) 1997 Aladdin Enterprises. All rights reserved.
- %
- % This file is part of Aladdin Ghostscript.
- %
- % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
- % or distributor accepts any responsibility for the consequences of using it,
- % or for whether it serves any particular purpose or works at all, unless he
- % or she says so in writing. Refer to the Aladdin Ghostscript Free Public
- % License (the "License") for full details.
- %
- % Every copy of Aladdin Ghostscript must include a copy of the License,
- % normally in a plain ASCII text file named PUBLIC. The License grants you
- % the right to copy, modify and redistribute Aladdin Ghostscript, but only
- % under certain conditions described in the License. Among other things, the
- % License requires that the copyright notice and this notice be preserved on
- % all copies.
-
- % writecff.ps
- % Write out a Type 1 font as CFF.
- % **************** THIS FILE DOES NOT WORK. ****************
- % **************** DON'T TRY TO USE IT. ****************
-
- currentglobal true setglobal
- (gs_cff.ps) runlibfile
- (t1tot2.ps) runlibfile
- setglobal
-
- 50 dict begin
-
- % ---------------- Standard strings/names ---------------- %
-
- /FontSetInit /ProcSet findresource begin mark
-
- /StandardSIDs StandardStrings length 1.5 mul cvi dict
- dup 0 1 StandardStrings length 1 sub {
- dup StandardStrings exch get exch put dup
- } for pop
-
- end counttomark 2 idiv { def } repeat
-
- % ---------------- Standard encodings ---------------- %
-
- % ---------------- Standard Charsets ---------------- %
-
- % ---------------- Output utilities ---------------- %
-
- % Free variables: f (output file), fpos (position in f).
-
- /advance { % <n> advance -
- fpos add /fpos exch store
- } def
- /next { % <byte> next -
- f exch write 1 advance
- } def
- /nextstring { % <string|name> nextstring -
- dup type /nametype eq { .namestring } if
- f 1 index writestring length advance
- } def
- /card8 % <card8> card8 -
- /next load
- def
- /card16 { % <card16> card16 -
- dup -8 bitshift next 255 and next
- } def
- /offset { % <offset> <offsize> offset -
- 1 sub -1 0 { -8 mul 2 copy bitshift 255 and next pop } for pop
- } def
- /sid % <sid> sid -
- /card16 load
- def
- /lenoffsize { % <length> lenoffsize <offsize>
- dup 255 le { pop 1 } { -8 bitshift lenoffsize 1 add } ifelse
- } def
- /Index { % [<string|name|null> ...] Index -
- % Calculate the maximum offset we need to be able to represent.
- 1 1 index { dup null eq { pop } { length add } ifelse } forall lenoffsize
- % stack: items offsize
- 1 index length card16
- dup next
- 1 2 index {
- % stack: items offsize pos item
- 1 index 3 index offset
- dup null eq { pop } { length add } ifelse
- } forall exch offset { nextstring } forall
- } def
- /idIndex { % <dict> <base> idIndex -
- 1 index length array 3 -1 roll {
- 3 index sub 2 index exch 3 -1 roll put
- } forall exch pop Index
- } def
- /stringid { % <string|name> stringid <sid>
- StandardSIDs 1 index .knownget {
- exch pop
- } {
- sids 1 index .knownget {
- exch pop
- } {
- StandardSIDs length sids length add sids 3 -1 roll 2 index put
- } ifelse
- } ifelse
- } def
- /.valuetypedict mark
- /booleantype { { 1 } { 0 } ifelse intvalue }
- /arraytype { { value } forall }
- /packedarraytype 1 index
- /stringtype { stringid intvalue }
- /nametype 1 index
- /realtype { realvalue }
- /integertype { intvalue }
- .dicttomark readonly def
- /value { % <obj> value -
- dup type .valuetypedict exch get exec
- } def
- /.realchardict mark
- 48 1 57 { dup 48 sub } for % digits
- 46 10 69 11 101 11 % . E e
- 45 { % - -- handle E- specially
- dup 15 and 11 eq { 15 or 12 } {
- dup 16#bf eq { pop 255 12 } { 14 } ifelse
- } ifelse
- }
- .dicttomark readonly def
- /realvalue { % <real> realvalue -
- =string cvs 255 exch {
- .realchardict exch get exec
- 1 index 15 and 15 ne { exch next 255 exch } if
- 1 index 240 and 240 eq { 4 bitshift 240 } { 15 } ifelse sub add
- } forall next
- } def
- /intvalue { % <int> intvalue -
- dup dup -107 ge exch 107 le and { 139 add next } {
- dup dup -1131 ge exch 0 lt and { neg 16#fa94 add card16 } {
- dup dup 1131 le exch 0 ge and { 16#f694 add card16 } {
- dup dup -32768 ge exch 32767 le and {
- 28 next 65535 and card16
- } {
- 29 next dup -16 bitshift 2 { 65535 and card16 } repeat
- } ifelse
- } ifelse
- } ifelse
- } ifelse
- } def
- /op { % <op> op -
- dup 32 ge { 12 next 32 sub } if next
- } def
- /vdef { % <obj> <op> vdef -
- exch value op
- } def
- /nedef { % <obj> <default> <op> nedef -
- exch 2 index eq { pop pop } { vdef } ifelse
- } def
- /Dict { % <dict> <opsdict> Dict -
- exch {
- % stack: opsdict key value
- 2 index 3 -1 roll .knownget {
- dup type /integertype eq { vdef } { exec } ifelse
- } {
- pop
- } ifelse
- } forall pop
- } def
- /collect { % <proc> collect <string>
- 10 dict begin
- /str 500 string def
- /spos 0 def
- /fpos 0 def
- /f {
- pop length spos add /spos exch store
- spos str length eq { /str str str concatstrings def } if
- str spos str length spos sub getinterval
- } /NullEncode filter def
- exec f closefile
- str 0 spos getinterval end
- } def
-
- % ------ Top (font) dictionary ------ %
-
- /topkeyops mark
- /version 0
- /Notice 1
- /Copyright 32
- /FullName 2
- /FamilyName 3
- /Weight 4
- /isFixedPatch { false 33 nedef }
- /ItalicAngle { 0 34 nedef }
- /UnderlinePosition { -100 35 nedef }
- /UnderlineThickness { 50 36 nedef }
- /PaintType { 0 37 nedef }
- /CharstringType { 2 38 nedef }
- /FontMatrix {
- true 0 1 5 {
- 2 index 1 index get {0.001 0 0 0.001 0 0} 3 -1 roll get eq and
- } for
- { pop } { value 39 op } ifelse
- }
- /UniqueID 13
- /FontBBox 5
- /StrokeWidth { 0 40 nedef }
- /XUID 14
- /FontInfo { topkeyops Dict }
- %**** Encoding
- /CharStrings { pop /charstringsoffset fpos store 32767 value 17 op }
- /Private { pop /privateoffset fpos store 32767 value 18 op }
- .dicttomark readonly def
-
- % ------ Private dictionary ------ %
-
- /deltarray { % [<num> ...] <op> deltarray -
- exch 0 exch { 1 index sub dup value add } forall pop op
- } def
- /privatekeyops mark
- /BlueValues { 6 deltarray }
- /OtherBlues { 7 deltarray }
- /FamilyBlues { 8 deltarray }
- /FamilyOtherBlues { 9 deltarray }
- /BlueScale { 0.039625 41 nedef }
- /BlueShift { 7 42 nedef }
- /BlueFuzz { 1 43 nedef }
- /StdHW 10
- /StdVW 11
- /StemSnapH { 44 deltarray }
- /StemSnapV { 45 deltarray }
- /ForceBold { false 46 nedef }
- /ForceBoldThreshold { 0 47 nedef }
- % Skip lenIV, it's always -1
- /LanguageGroup { 0 49 nedef }
- /ExpansionFactor { 0.06 50 nedef }
- /initialRandomSeed { 0 51 nedef }
- /Subrs { pop /subroffset fpos store 32767 value 19 op }
- /defaultWidthX { 0 20 nedef }
- /nominalWidthX { 0 20 nedef }
- .dicttomark readonly def
-
- % ------ Main program ------ %
-
- /putoffset { % <str> <index> <offset> putoffset -
- % The saved index points to the 29 byte, so we must add 1.
- 3 copy exch 1 add exch -8 bitshift put
- exch 2 add exch 255 and put
- } def
-
- /writecff { % <file> [<font> ...] writecff -
- 30 dict begin
- /fonts exch cvlit def
- /cff exch cvlit def
-
- /f cff def
- /fpos 0 def
-
- % We need to pre-construct all the strings so that we know
- % the offsets to fill in.
-
- /names { [ fonts { /FontName get } forall ] Index } collect def
- /sids 20 dict def
- /subrcounts fonts length 200 mul dict def
- /subrs [ fonts {
- /font 1 index def
- /Private get /Subrs .knownget {
- [ exch {
- dup null ne {
- dup subrcounts exch 2 copy .knownget { 1 add } { 1 } ifelse put
- t1tot2
- } if
- } forall ] { Index } collect
- } {
- <>
- } ifelse
- } forall ] def
- % At this point we should use subrcounts to move any duplicated
- % subrs from local to global....
- DEBUG {
- 0 subrcounts { exch pop add } forall =only ( total subrs) =
- subrcounts length =only ( distinct subrs) =
- 0 subrcounts { 1 sub exch length mul add } forall =only ( space for duplicates) =
- } if
- %****** FOLLOWING IS WRONG, WRONG, WRONG ******%
- /charstrings [ fonts {
- /font 1 index def
- /CharStrings get [ exch {
- exch pop t1tot2
- } forall ] { Index } collect
- } forall ] def
- /subroffset null def
- /privates [ 0 1 fonts length 1 sub {
- /i exch def
- /pstr fonts i get /Private get { privatekeyops Dict } collect def
- /len pstr length def
- pstr subroffset len putoffset %**** WRONG ****
- pstr
- } for ] def
- /strings { sids StandardSIDs length idIndex } collect def
-
- % Now we can write the real file.
- % Header
- DEBUG { (header ) print fpos == } if
- <01 00 04 02> nextstring
- % Name Index
- DEBUG { (names ) print fpos == } if
- names nextstring
- %****** FOLLOWING IS WRONG, WRONG, WRONG -- OFFSETS MISSING ******%
- % Top Dicts
- DEBUG { (tops ) print fpos == } if
- /charstringsoffset null def
- /privateoffset null def
- fonts {
- dup length 2 add dict copy
- dup /CharstringType 2 put
- topkeyops Dict
- } forall
- % String Index
- DEBUG { (strings ) print fpos == } if
- strings nextstring
- % Charstrings Indexes
- DEBUG { (charstrings) print } if
- charstrings { DEBUG { ( ) print fpos =only } if nextstring } forall
- DEBUG { () = } if
- % Private Dicts
- DEBUG { (privates) print } if
- privates { DEBUG { ( ) print fpos =only } if nextstring } forall
- DEBUG { () = } if
- % Local Subr Indexes
- DEBUG { (subrs) print } if
- subrs { DEBUG { ( ) print fpos =only } if nextstring } forall
- DEBUG { () = } if
-
- DEBUG { (end ) print fpos = flush } if
- end
- } def
-
- % ---------------- Wrap up ---------------- %
-
- currentdict readonly end
- /writecffdict exch def
-
- /writecff {
- writecffdict begin writecff end
- } def
-
- % Test case
- (t.cff) (w) file dup
- [ {
- /Bookman-Demi
- /Bookman-DemiItalic
- /Bookman-Light
- /Bookman-LightItalic
- /Courier
- /Courier-Oblique
- /Courier-Bold
- /Courier-BoldOblique
- /AvantGarde-Book
- /AvantGarde-BookOblique
- /AvantGarde-Demi
- /AvantGarde-DemiOblique
- /Helvetica
- /Helvetica-Oblique
- /Helvetica-Bold
- /Helvetica-BoldOblique
- /Helvetica-Narrow
- /Helvetica-Narrow-Oblique
- /Helvetica-Narrow-Bold
- /Helvetica-Narrow-BoldOblique
- /Palatino-Roman
- /Palatino-Italic
- /Palatino-Bold
- /Palatino-BoldItalic
- /NewCenturySchlbk-Roman
- /NewCenturySchlbk-Italic
- /NewCenturySchlbk-Bold
- /NewCenturySchlbk-BoldItalic
- /Times-Roman
- /Times-Italic
- /Times-Bold
- /Times-BoldItalic
- /Symbol
- /ZapfChancery-MediumItalic
- /ZapfDingbats
- } { findfont } forall
- ] writecff closefile
-